<template>
  <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
    <h1 class="title">权限管理</h1>
    <el-form-item prop="username">
      <el-input type="text" v-model="ruleForm2.username" auto-complete="off" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item prop="password">
      <el-input type="password" v-model="ruleForm2.password" auto-complete="off" placeholder="密码"></el-input>
    </el-form-item>
    <el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox>
    <el-form-item style="width:100%;">
      <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  export default {
    data() {
      return {
        logining: false,
        ruleForm2: {
          username: '',
          password: ''
        },
        rules2: {
          username: [
            { required: true, message: '请输入账号', trigger: 'blur' },
            //{ validator: validaePass }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            //{ validator: validaePass2 }
          ]
        },
        checked: true
      };
    },
    methods: {
      handleSubmit2(ev) {
      this.logining = true;
      var _this = this;
      var data = {
            username:this.ruleForm2.username,
            password:this.ruleForm2.password
      };
      if(this.ruleForm2.username!='' && this.ruleForm2.password!=''){
       $.ajax({  
              data:JSON.stringify(data),       //要发送的数据
              url:"http://101.200.56.75/apis/shiro/login", //url地址 
              type:"POST",           //发送的方式  
              dataType:"JSON", 
                  contentType:'application/json;charset=UTF-8', 
              success:function(msg){  //处理正确时的信息  
                if(msg.payload.success==1){
                  sessionStorage.setItem("key",msg.payload.token.tokenname);
                  sessionStorage.setItem("username",msg.payload.token.tokenusername);
                  sessionStorage.setItem("rolename",msg.payload.role);
                  _this.$message({message: '登录成功',type: 'success'});
                  _this.logining = false;
                  _this.$router.push({ path: '/user' }); 
                }else{
                  _this.$alert(msg.payload.error,{
                  type:'error'
                })
                };
                _this.logining = false;
              },error:function(){
                      _this.$message({message: '登录失败',type: 'error'});
                      _this.logining = false;
              }
          }); }else
          {
          _this.$alert("用户名或密码不能为空！！",{
          type:'warning'
          });
          _this.logining = false;
          } 
            } 
      }
      }
</script>

<style lang="scss" scoped>
  .login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    .title {
      margin: 0px auto 40px auto;
      text-align: center;
      color: #505458;
    }
    .remember {
      margin: 0px 0px 35px 0px;
    }
  }
</style>